import tomllib
import sys


class Toml:
    def __init__(self, name):
        with open(name, "rb") as f:
            self.content = tomllib.load(f)

    def mes(self):
        m = self.content["workspace"]["members"]
        s = ' '.join(m)
        return s


if __name__ == '__main__':
    argv = sys.argv
    if len(argv) < 3:
        print("Command error.")
        exit(1)

    cmd = sys.argv[1]
    path = sys.argv[2] + "/Cargo.toml"

    if cmd == "ver":
        with open(path, 'r') as file:
            for line in file:
                if line.startswith("version ="):
                    s = line.find("\"")
                    e = line.rfind("\"")
                    ver = line[s + 1:e]
                    ret = ver.split(".")
                    tmp = "%s.%s" % (ret[0], ret[1])
                    print(tmp)

                    break
    if cmd == "mes":
        name = Toml(path)
        print(name.mes())
